import React, { useEffect, useState, useRef } from 'react';
import { createRoot } from 'react-dom/client';
import ReactDOM from 'react-dom';
import { defaultHolidays } from '../lib/holidays.js';
import { getAuthAxios } from '../lib/authAxios.js';
import { WarnTableDrawer } from './script_warnTable.jsx';
// 主组件
const App = () => {
  const myAxios = getAuthAxios();
  const holidays = useState(defaultHolidays);
  window.setMyGlobalVar('warnTableData', []);
  useEffect(() => {
    function onGlobalVarChange(e) {
      if ('全部工单' == window.getMyGlobalVar('activeTabName')) {
        initYuJing();
      }
      window.getMyGlobalVar('activeTabName');
    }
    window.addEventListener('MY_GLOBAL_VAR_CHANGE', onGlobalVarChange);
    return () => window.removeEventListener('MY_GLOBAL_VAR_CHANGE', onGlobalVarChange);
  }, []);
  const initYuJing = () => {
    const iframe = document.querySelector('#f787d3220f34c72637a208ca80415724870e8c1ddec5d4129a283914dc8cd6ac');
    const iframeDom = iframe.contentDocument || iframe.contentWindow.document;
    if (!iframeDom) return;
    // console.log(iframeDom, '--------------------------------------------------btnDom--------------------------------------')
    const btnDom = iframeDom.querySelector(
      '#app > div:nth-child(2) > div > div.card-box.query-card-box > div > div > div.card-third-box_yx > div.card-root > form > div:nth-child(13) > div > div > div > button.el-button.el-button--primary.el-button--mini'
    );
    btnDom &&
      btnDom.addEventListener('click', () => {
        const TableEl = iframeDom.querySelector(
          '#app > div:nth-child(2) > div > div.card-box.query-card-box > div > div > div.card-third-box_yx > div:nth-child(3) > div > div.table-box > div'
        );
        observeChanges(
          TableEl,
          tableDom => {
            const warningRows = []; //理论上是预警的数据
            window.setMyGlobalVar('warnTableData', []);
            const now = new Date();
            const listDom = iframeDom.querySelectorAll(
              '#app > div:nth-child(2) > div > div.card-box.query-card-box > div > div > div.card-third-box_yx > div:nth-child(3) > div > div.table-box > div > div.el-table__body-wrapper.is-scrolling-left > table > tbody > tr'
            );
            if (!listDom) return;
            const listDomRight = iframeDom.querySelectorAll(
              '#app > div:nth-child(2) > div > div.card-box.query-card-box > div > div > div.card-third-box_yx > div:nth-child(3) > div > div.table-box > div > div.el-table__fixed-right > div.el-table__fixed-body-wrapper > table > tbody > tr'
            );
            const listDomLeft = iframeDom.querySelectorAll(
              '#app > div:nth-child(2) > div > div.card-box.query-card-box > div > div > div.card-third-box_yx > div:nth-child(3) > div > div.table-box > div > div.el-table__fixed > div.el-table__fixed-body-wrapper > table > tbody > tr'
            );
            listDom.forEach((tr, index) => {
              const fifthTd = tr.querySelector('a');
              fifthTd &&
                fifthTd.addEventListener('click', () => {
                  const tds = Array.from(tr.children);
                  const rowData = tds.map(td => td.textContent.trim());
                  let warningObj = {
                    workOrderNo: '', // 工单编号
                    processName: '', //流程名称
                    nodeName: '', //环节名称
                    supplyUnit: '', //供电单位u
                    countyName: '', //区县

                    nodeStartTime: '', //环节开始时间
                    nodeEndTime: '', //环节结束时间
                    processStartTime: '', //流程开始时间
                    startUser: '', //发起负责人
                    receiver: '', // 接收人

                    fields: '', // 字段（哪个字段预警）
                    alertTime: dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss') // 提醒时间
                  };
                  warningObj.workOrderNo = rowData[2];
                  warningObj.processName = rowData[5];
                  warningObj.nodeName = rowData[6];
                  warningObj.supplyUnit = rowData[9];
                  warningObj.countyName = rowData[10];

                  warningObj.nodeStartTime = rowData[11] ? dayjs(rowData[11]).format('YYYY-MM-DD HH:mm:ss') : '';
                  warningObj.nodeEndTime = rowData[12] ? dayjs(rowData[12]).format('YYYY-MM-DD HH:mm:ss') : '';
                  warningObj.processStartTime = rowData[15] ? dayjs(rowData[15]).format('YYYY-MM-DD HH:mm:ss') : '';
                  warningObj.startUser = rowData[22];
                  warningObj.receiver = rowData[26];
                  warningObj.fields = '';
                  console.log('warningObj', warningObj);
                  window.setMyGlobalVar('warningObj', warningObj);
                });

              //样式初始化
              tr.style.backgroundColor = 'white';
              listDomLeft[index].style.backgroundColor = 'white';
              listDomRight[index].style.backgroundColor = 'white';
              const tdList = tr.children;
              const nodeNo = tdList[2].textContent.trim(); // 工单编号
              const flowName = tdList[5].textContent.trim(); // 流程名称
              const nodeName = tdList[6].textContent.trim(); // 环节名称
              const mgtOrgCodeName = tdList[9].textContent.trim(); // 供电单位
              const countyCodeName = tdList[10].textContent.trim(); // 所属区县
              const status = tdList[24].textContent.trim(); // 工单状态
              const processStartTime = tdList[15].textContent ? new Date(tdList[15].textContent.trim()) : ''; // 流程开始时间
              const nodeStartTime = tdList[11].textContent.trim() ? new Date(tdList[11].textContent.trim()) : ''; // 环节开始时间
              const nodeEndTime = tdList[12].textContent.trim() ? new Date(tdList[12].textContent.trim()) : ''; // 环节结束时间
              const initUser = tdList[22].textContent.trim(); // 发起负责人
              const signUser = tdList[27].textContent.trim(); // 发起负责人

              // 检查1：全流程时限≤5个工作日且工单在途
              if (status === '在途') {
                const remainingWorkdays = triggerWarning(processStartTime, now);
                // 上门服务单独处理---
                if (remainingWorkdays <= 5 && remainingWorkdays >= 0 && nodeName != '上门服务') {
                  // 5个工作日触发预警
                  tr.style.backgroundColor = 'rgba(255,132,0,0.2)';
                  listDomLeft[index].style.backgroundColor = 'rgba(255,132,0,0.2)';
                  listDomRight[index].style.backgroundColor = 'rgba(255,132,0,0.2)';
                  warningRows.push({
                    dom: tr,
                    type: '全流程预警',
                    nodeNo,
                    nodeName,
                    color: 'rgba(255,132,0,0.2)',
                    daysRemaining: remainingWorkdays,
                    timeOut: remainingWorkdays,
                    timeOutUnit: '天',
                    flowName: flowName,
                    mgtOrgCodeName: mgtOrgCodeName,
                    countyCodeName: countyCodeName,
                    initUser: initUser,
                    processStartTime: processStartTime,
                    nodeStartTime: nodeStartTime,
                    nodeEndTime: nodeEndTime,
                    signUser
                  });
                  return; // 满足条件后不再检查其他条件
                } else if (remainingWorkdays < 0) {
                  tr.style.backgroundColor = 'rgba(255,0,0,0.2)';
                  listDomLeft[index].style.backgroundColor = 'rgba(255,0,0,0.2)';
                  listDomRight[index].style.backgroundColor = 'rgba(255,0,0,0.2)';
                  warningRows.push({
                    dom: tr,
                    type: '超时预警',
                    nodeNo,
                    nodeName,
                    color: 'rgba(255,0,0,0.2)',
                    daysRemaining: remainingWorkdays,
                    timeOut: Math.abs(remainingWorkdays),
                    timeOutUnit: '天',
                    flowName: flowName,
                    mgtOrgCodeName: mgtOrgCodeName,
                    countyCodeName: countyCodeName,
                    initUser: initUser,
                    processStartTime: processStartTime,
                    nodeStartTime: nodeStartTime,
                    nodeEndTime: nodeEndTime,
                    signUser
                  });
                  return; // 满足条件后不再检查其他条件
                }

                // 检查2：特定环节12小时未处理（含非工作日）
                if (['营业厅受理', '线上业务受理'].includes(nodeName)) {
                  const hoursDiff = getHoursDiff(nodeStartTime, now);
                  if (nodeEndTime) return;
                  if (hoursDiff >= 12 && hoursDiff <= 24) {
                    tr.style.backgroundColor = 'rgba(125,127,229,0.2)';
                    listDomLeft[index].style.backgroundColor = 'rgba(125,127,229,0.2)';
                    listDomRight[index].style.backgroundColor = 'rgba(125,127,229,0.2)';
                    warningRows.push({
                      dom: tr,
                      type: '环节超时预警',
                      nodeNo,
                      nodeName,
                      color: 'rgba(125,127,229,0.2)',
                      hoursElapsed: hoursDiff,
                      node: nodeName,
                      timeOut: hoursDiff,
                      timeOutUnit: '小时',
                      flowName: flowName,
                      mgtOrgCodeName: mgtOrgCodeName,
                      countyCodeName: countyCodeName,
                      initUser: initUser,
                      processStartTime: processStartTime,
                      nodeStartTime: nodeStartTime,
                      nodeEndTime: nodeEndTime,
                      signUser
                    });
                    return;
                  } else if (hoursDiff >= 24) {
                    tr.style.backgroundColor = 'rgba(255,0,0,0.2)';
                    listDomLeft[index].style.backgroundColor = 'rgba(255,0,0,0.2)';
                    listDomRight[index].style.backgroundColor = 'rgba(255,0,0,0.2)';
                    warningRows.push({
                      dom: tr,
                      type: '超时预警',
                      nodeNo,
                      nodeName,
                      color: 'rgba(255,0,0,0.2)',
                      hoursElapsed: hoursDiff,
                      node: nodeName,
                      timeOut: hoursDiff,
                      timeOutUnit: '天',
                      flowName: flowName,
                      mgtOrgCodeName: mgtOrgCodeName,
                      countyCodeName: countyCodeName,
                      initUser: initUser,
                      processStartTime: processStartTime,
                      nodeStartTime: nodeStartTime,
                      nodeEndTime: nodeEndTime,
                      signUser
                    });
                    return; // 满足条件后不再检查其他条件
                  }
                }

                // 检查3：上门服务48工作小时未处理（仅工作日）
                if (nodeName === '上门服务') {
                  const workHours = getWorkdayHoursDiff(nodeStartTime, now);
                  if (nodeEndTime) return;
                  if (workHours >= 48 && workHours <= 72) {
                    tr.style.backgroundColor = 'rgba(125,127,229,0.2)';
                    listDomLeft[index].style.backgroundColor = 'rgba(125,127,229,0.2)';
                    listDomRight[index].style.backgroundColor = 'rgba(125,127,229,0.2)';
                    warningRows.push({
                      dom: tr,
                      type: '上门服务预警',
                      nodeNo,
                      nodeName,
                      color: 'rgba(125,127,229,0.2)',
                      workHoursElapsed: workHours,
                      timeOut: workHours,
                      timeOutUnit: '小时',
                      flowName: flowName,
                      mgtOrgCodeName: mgtOrgCodeName,
                      countyCodeName: countyCodeName,
                      initUser: initUser,
                      processStartTime: processStartTime,
                      nodeStartTime: nodeStartTime,
                      nodeEndTime: nodeEndTime,
                      signUser
                    });
                    return;
                  } else if (workHours >= 72) {
                    tr.style.backgroundColor = 'rgba(255,0,0,0.2)';
                    listDomLeft[index].style.backgroundColor = 'rgba(255,0,0,0.2)';
                    listDomRight[index].style.backgroundColor = 'rgba(255,0,0,0.2)';
                    warningRows.push({
                      dom: tr,
                      type: '超时预警',
                      nodeNo,
                      nodeName,
                      color: 'rgba(255,0,0,0.2)',
                      workHoursElapsed: workHours,
                      timeOut: workHours,
                      timeOutUnit: '小时',
                      flowName: flowName,
                      mgtOrgCodeName: mgtOrgCodeName,
                      countyCodeName: countyCodeName,
                      initUser: initUser,
                      processStartTime: processStartTime,
                      nodeStartTime: nodeStartTime,
                      nodeEndTime: nodeEndTime,
                      signUser
                    });
                    return; // 满足条件后不再检查其他条件
                  }
                }

                // 检查4：装表接电24工作小时未处理（仅工作日）
                if (nodeName === '装表接电') {
                  const workHours = getWorkdayHoursDiff(nodeStartTime, now);
                  if (nodeEndTime) return;
                  if (workHours >= 24 && workHours <= 48) {
                    tr.style.backgroundColor = 'rgba(125,127,229,0.2)';
                    listDomLeft[index].style.backgroundColor = 'rgba(125,127,229,0.2)';
                    listDomRight[index].style.backgroundColor = 'rgba(125,127,229,0.2)';
                    warningRows.push({
                      dom: tr,
                      type: '装表接电预警',
                      nodeNo,
                      nodeName,
                      color: 'rgba(125,127,229,0.2)',
                      workHoursElapsed: workHours,
                      timeOut: workHours,
                      timeOutUnit: '小时',
                      flowName: flowName,
                      mgtOrgCodeName: mgtOrgCodeName,
                      countyCodeName: countyCodeName,
                      initUser: initUser,
                      processStartTime: processStartTime,
                      nodeStartTime: nodeStartTime,
                      nodeEndTime: nodeEndTime,
                      signUser
                    });
                  } else if (workHours >= 48) {
                    tr.style.backgroundColor = 'rgba(255,0,0,0.2)';
                    listDomLeft[index].style.backgroundColor = 'rgba(255,0,0,0.2)';
                    listDomRight[index].style.backgroundColor = 'rgba(255,0,0,0.2)';
                    warningRows.push({
                      dom: tr,
                      type: '超时预警',
                      nodeNo,
                      nodeName,
                      color: 'rgba(255,0,0,0.2)',
                      workHoursElapsed: workHours,
                      timeOut: workHours,
                      timeOutUnit: '小时',
                      flowName: flowName,
                      mgtOrgCodeName: mgtOrgCodeName,
                      countyCodeName: countyCodeName,
                      initUser: initUser,
                      processStartTime: processStartTime,
                      nodeStartTime: nodeStartTime,
                      nodeEndTime: nodeEndTime,
                      signUser
                    });
                    return; // 满足条件后不再检查其他条件
                  }
                }
              }
            });
            let dataList = {
              num1: 0,
              num2: 0,
              num3: 0
            };
            // console.log(warningRows, 'warningRowswarningRowswarningRowswarningRowswarningRowswarningRows===================================================================')
            warningRows.map(item => {
              //添加预警数量显示
              if (item.type == '超时预警') {
                dataList.num1 += 1;
                //添加鼠标移入展示
                // showDaysOnHover(item.dom, item.timeOut)
              } else if (item.type == '全流程预警') {
                dataList.num2 += 1;
                //添加鼠标移入展示
                showDaysOnHover(item.dom, item.timeOut);
              } else if (item.type == '上门服务预警' || item.type == '装表接电预警' || item.type == '环节超时预警') {
                dataList.num3 += 1;
                //添加鼠标移入展示
                showDaysOnHover(item.dom, item.timeOut, '小时');
              }
              // //添加鼠标移入展示
              // showDaysOnHover(item.dom, item.timeOut)
            });
            createTable(dataList);
            saveWarningRow(warningRows);
            let list = warningRows.map(row => ({
              workOrderNo: row.nodeNo,
              warningType: row.type,
              timeLimit: row.timeOut + row.timeOutUnit,
              nodeName: row.nodeName,
              supplyUnit: row.mgtOrgCodeName
            }));
            window.setMyGlobalVar('warnTableData', [...window.getMyGlobalVar('warnTableData'), ...list]);
          },
          { attributes: false }
        );
      });
    function saveWarningRow(warningRows) {
      let warningList = [];
      warningRows.forEach(item => {
        let object = {
          alertType: '',
          alertLimit: '',
          workOrderNo: '',
          processName: '',
          nodeName: '',

          supplyUnit: '',
          countyName: '',
          nodeStartTime: '',
          nodeEndTime: '',
          processStartTime: '',
          startUser: '',
          signUser: '',

          alertTime: dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
        };
        object.alertType = item.type;
        let limitTime = 0;
        if (item.timeOutUnit == '小时') {
          limitTime = item.timeOut;
        } else {
          limitTime = Number(item.timeOut) * 24;
        }
        object.alertLimit = limitTime;

        object.workOrderNo = item.nodeNo;
        object.processName = item.flowName;
        object.nodeName = item.nodeName;

        object.supplyUnit = item.mgtOrgCodeName;
        object.countyName = item.countyCodeName;
        object.nodeStartTime = item.nodeStartTime ? dayjs(item.nodeStartTime).format('YYYY-MM-DD HH:mm:ss') : '';
        object.nodeEndTime = item.nodeEndTime ? dayjs(item.nodeEndTime).format('YYYY-MM-DD HH:mm:ss') : '';
        object.processStartTime = item.processStartTime ? dayjs(item.processStartTime).format('YYYY-MM-DD HH:mm:ss') : '';

        object.startUser = item.initUser;
        object.signUser = item.signUser;
        warningList.push(object);
      });
      if (!warningList.length) {
        return;
      }
      myAxios
        .post('http://10.158.212.196:34002/yxjc/api/yxjc/v1/yxjcAllertMsg/addBatch', warningList)
        .then(response => {
          console.log('数据已成功发送:', response.data);
        })
        .catch(error => {
          console.error('发送数据失败:', error);
        });
    }

    // 工作日计算函数（排除周末）
    function isWeekday(date) {
      return date.getDay() !== 0 && date.getDay() !== 6;
    }

    // 计算工作日差（不含周末）弃用
    function getWorkdayDiff(startDate, endDate) {
      let count = 0;
      const curDate = new Date(startDate.getTime());
      while (curDate <= endDate) {
        if (isWeekday(curDate)) {
          count++;
        }
        curDate.setDate(curDate.getDate() + 1);
      }
      return count;
    }

    // 计算小时差（含非工作日）
    function getHoursDiff(startTime, endTime) {
      return Math.floor((endTime - startTime) / (1000 * 60 * 60));
    }
    // 计算工作日小时数（辅助函数）
    function getWorkdayHoursDiff(startTime, endTime) {
      let hours = 0;
      const curTime = new Date(startTime.getTime());

      while (curTime < endTime) {
        if (isWeekday(curTime)) {
          hours++;
        }
        curTime.setHours(curTime.getHours() + 1);

        // 避免无限循环
        if (hours > 10000) break;
      }

      return hours;
    }

    //时间取整到天数
    function calculateDays(time) {
      if (time == 0) {
        return 0;
      }
      return Math.ceil(time / 24);
    }
    //创建预警显示
    function createTable(dataList) {
      const oldListDom = iframeDom.querySelector('#listDom1');
      if (oldListDom) oldListDom.remove();
      const listDom = document.createElement('div');
      listDom.id = 'listDom1';
      listDom.style.fontSize = '16px';
      listDom.style.position = 'absolute';
      listDom.style.zIndex = '999';
      listDom.style.top = '216px';
      listDom.style.left = '83px';
      listDom.style.display = 'flex';
      listDom.innerHTML =
        '<div style="color:rgb(255,0,0);margin-right:40px;">超时工单： ' +
        dataList.num1 +
        ' 条</div><div style="color:rgb(255,132,0);margin-right:40px;">全流程限时预警： ' +
        dataList.num2 +
        ' 条</div><div style="color:rgb(125,127,229)">环节限时预警： ' +
        dataList.num3 +
        ' 条</div>';
      const cardRoot = iframeDom.querySelector('.card-root');
      cardRoot.appendChild(listDom);
    }

    //创建移入显示

    function showDaysOnHover(element, days, title = '天', options = {}) {
      // 合并默认配置
      const config = {
        position: 'bottom',
        offset: 5,
        ...options
      };

      // 创建提示元素
      const tooltip = document.createElement('div');
      tooltip.textContent = '剩余' + days + title;
      tooltip.style.position = 'absolute';
      tooltip.style.padding = '4px 8px';
      tooltip.style.background = '#333';
      tooltip.style.color = '#fff';
      tooltip.style.borderRadius = '4px';
      tooltip.style.fontSize = '12px';
      tooltip.style.opacity = '0';
      tooltip.style.transition = 'opacity 0.2s';
      tooltip.style.pointerEvents = 'none';
      tooltip.style.zIndex = '1000';
      tooltip.style.whiteSpace = 'nowrap';

      // 添加到DOM
      iframeDom.body.appendChild(tooltip);

      // 鼠标移入事件
      element.addEventListener('mouseenter', e => {
        // 获取元素位置
        const rect = element.getBoundingClientRect();

        // 计算提示框位置
        if (config.position === 'bottom') {
          tooltip.style.top = rect.bottom + config.offset + window.scrollY + 'px';
        } else {
          tooltip.style.top = rect.top - tooltip.offsetHeight - config.offset + window.scrollY + 'px';
        }

        // 水平居中
        tooltip.style.left = rect.left + (rect.width - tooltip.offsetWidth) / 2 + window.scrollX + 'px';

        // 显示提示
        tooltip.style.opacity = '1';
      });

      // 鼠标移出事件
      element.addEventListener('mouseleave', () => {
        tooltip.style.opacity = '0';
      });

      // 鼠标移动事件（跟随鼠标）
      element.addEventListener('mousemove', e => {
        tooltip.style.left = e.pageX - tooltip.offsetWidth / 2 + 'px';
      });

      // 元素移除时清理提示
      const observer = new MutationObserver(() => {
        if (!iframeDom.body.contains(element)) {
          tooltip.remove();
          observer.disconnect();
        }
      });
      observer.observe(iframeDom.body, { childList: true, subtree: true });
    }
  };

  /**
   * 检查日期是否为节假日
   * @param {Date} date - 要检查的日期
   * @param {string[]} holidays - 节假日列表，格式为 "YYYY-MM-DD"
   * @returns {boolean} 是否为节假日
   */
  function isHoliday(date, holidays) {
    const formattedDate = date.toISOString().split('T')[0]; // 格式化为 YYYY-MM-DD
    return holidays.includes(formattedDate);
  }

  /**
   * 计算两个日期之间的工作日数（周一到周五，排除周末和节假日）
   * @param {Date} startDate - 开始日期
   * @param {Date} endDate - 结束日期
   * @param {string[]} holidays - 节假日列表
   * @returns {number} 工作日数
   */
  function getWorkdaysBetween(startDate, endDate, holidays) {
    let workdays = 0;
    let current = new Date(startDate);
    current.setHours(0, 0, 0, 0); // 归零时间部分
    endDate = new Date(endDate);
    endDate.setHours(0, 0, 0, 0);
    if (current <= endDate) {
      while (current <= endDate) {
        const dayOfWeek = current.getDay();
        if (dayOfWeek !== 0 && dayOfWeek !== 6 && !isHoliday(current, holidays)) {
          workdays++;
        }
        current.setDate(current.getDate() + 1);
      }
    } else {
      while (current >= endDate) {
        const dayOfWeek = current.getDay();
        if (dayOfWeek !== 0 && dayOfWeek !== 6 && !isHoliday(current, holidays)) {
          workdays--;
        }
        current.setDate(current.getDate() + 1);
      }
    }
    return workdays;
  }

  /**
   * 在指定日期后添加指定工作日数（排除周末和节假日）
   * @param {Date} startDate - 开始日期
   * @param {number} workdays - 要添加的工作日数
   * @param {string[]} holidays - 节假日列表
   * @returns {Date} 结果日期
   */
  function addWorkdays(startDate, workdays, holidays) {
    let current = new Date(startDate);
    let remainingWorkdays = workdays;

    while (remainingWorkdays > 0) {
      current.setDate(current.getDate() + 1);
      const dayOfWeek = current.getDay();
      if (dayOfWeek !== 0 && dayOfWeek !== 6 && !isHoliday(current, holidays)) {
        remainingWorkdays--;
      }
    }

    return current;
  }

  /**
   * 判断是否触发工单预警
   * @param {string|Date} startTime - 流程开始时间（ISO字符串或Date对象）
   * @param {string} status - 工单状态
   * @param {Date} [currentTime] - 当前时间（可选，默认为当前时间）
   * @param {string[]} [holidays] - 节假日列表，格式为 "YYYY-MM-DD"（可选）
   * @returns {boolean} 是否触发预警
   */
  function triggerWarning(startTime, currentTime = new Date()) {
    // 使用传入的节假日或默认列表
    const holidayList = holidays;

    // 解析开始时间
    const startDate = new Date(startTime);
    if (isNaN(startDate.getTime())) {
      console.error('Invalid startTime format');
      return false;
    }

    // 计算全流程办理时限（开始时间 + 15个工作日）
    const deadline = addWorkdays(startDate, 15, holidayList);

    // 计算当前时间到办理时限的剩余工作日
    const remainingWorkdays = getWorkdaysBetween(currentTime, deadline, holidayList);

    return remainingWorkdays;
    // return remainingWorkdays > 0  没超过deadline,remainingWorkdays <  0 已超期
  }

  // 示例用法
  // const start = new Date('2025-01-06T09:00:00'); // 2025年1月6日（周一）
  // const holidays = ['2025-01-29', '2025-01-30']; // 春节部分日期
  // console.log(triggerWarning(start, '在途', new Date('2025-01-27T15:20:00'), holidays)); // true（考虑节假日后，剩余≤5工作日）

  return null;
};

// 渲染函数
const init = () => {
  const container = document.createElement('div');
  container.style.fontSize = '14px';
  document.body.appendChild(container);
  const root = createRoot(container);
  root.render(<App />);
};

// 执行初始化
init();
